﻿using System;

using FluentAssertions;

using LambdaGp.Core;
using LambdaGp.Operators;
using LambdaGp.Operators.Terminals;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LambdaGp.Tests
{
    [TestClass]
    public class IndividualTests
    {
        [TestMethod]
        public void Can_create_individual()
        {
            new Individual();
        }

        [TestMethod]
        public void Individuals_have_VariableInstances_for_variables()
        {
            Population population = TestPopulationFactory.CreatePopulation();
            population.RunGeneration();
            Individual individual = population.CurrentGeneration[0];

            Variable.GetVariable(individual, "x").Should().NotBeNull();
            Variable.GetVariable(individual, "y").Should().NotBeNull();
            Variable.GetVariable(individual, "z").Should().NotBeNull();
        }

        [TestMethod]
        public void Cloned_individuals_dont_effect_eachothers_variable_values()
        {
            Population population = TestPopulationFactory.CreatePopulation();
            population.RunGeneration();
            population.RunGeneration();

            Individual first = population.CurrentGeneration[0];
            Variable.GetVariable(first, "x").Value = 10;
            Individual second = first.Clone();
            Variable.GetVariable(second, "x").Value = 15;

            double difference = Math.Abs(first.GetVariable("x").Value - second.GetVariable("x").Value);
            difference.Should().BeGreaterThan(4);
        }

        [TestMethod]
        public void Different_individuals_dont_effect_eachothers_variable_values()
        {
            Population population = TestPopulationFactory.CreatePopulation();
            population.RunGeneration();
            population.RunGeneration();

            Individual first = population.CurrentGeneration[0];
            first.GetVariable("x").Value = 10;
            Individual second = population.CurrentGeneration[1];
            second.GetVariable("x").Value = 15;

            double difference = Math.Abs(first.GetVariable("x").Value - second.GetVariable("x").Value);
            difference.Should().BeGreaterThan(4);
        }
    }
}
